package com.ruoyi.znjc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.znjc.domain.ZnjcMessages;
import com.ruoyi.znjc.service.IZnjcMessagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息Controller
 * 
 * @author ruoyi
 * @date 2025-07-26
 */
@RestController
@RequestMapping("/znjc/messages")
public class ZnjcMessagesController extends BaseController
{
    @Autowired
    private IZnjcMessagesService znjcMessagesService;

    /**
     * 查询消息列表
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZnjcMessages znjcMessages)
    {
        startPage();
        List<ZnjcMessages> list = znjcMessagesService.selectZnjcMessagesList(znjcMessages);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnjcMessages znjcMessages)
    {
        List<ZnjcMessages> list = znjcMessagesService.selectZnjcMessagesList(znjcMessages);
        ExcelUtil<ZnjcMessages> util = new ExcelUtil<ZnjcMessages>(ZnjcMessages.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(znjcMessagesService.selectZnjcMessagesByMessageId(messageId));
    }

    /**
     * 新增消息
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnjcMessages znjcMessages)
    {
        return toAjax(znjcMessagesService.insertZnjcMessages(znjcMessages));
    }

    /**
     * 修改消息
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnjcMessages znjcMessages)
    {
        return toAjax(znjcMessagesService.updateZnjcMessages(znjcMessages));
    }

    /**
     * 删除消息
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(znjcMessagesService.deleteZnjcMessagesByMessageIds(messageIds));
    }

    /**
     * 根据会话ID查询消息列表
     */
    @PreAuthorize("@ss.hasPermi('znjc:messages:list')")
    @GetMapping("/conversation/{conversationId}")
    public AjaxResult listByConversationId(@PathVariable Long conversationId)
    {
        List<ZnjcMessages> list = znjcMessagesService.selectMessagesByConversationId(conversationId);
        return AjaxResult.success(list);
    }


}
